/*
Responsible for the loading and playing of Frame animations
 */

// This is a great idea for making a Processing Contributed Library

class Animation {

  String name;
  PImage[] images;
  int number_of_frames;

  boolean running = true;
  int frame=0; 

  float x_loc;
  float y_loc;

  Animation(String name, int number_of_frames, float x_loc, float y_loc) {
    this.name = name;
    this.number_of_frames = number_of_frames;

    images = new PImage[number_of_frames];
    for(int x=0;x < number_of_frames; x++) {
      images[x] = loadImage( "data/"+name+"/"+(x+1)+".png");
    }

    this.x_loc = x_loc;
    this.y_loc = y_loc;
  }

  void play() {
    if(running) {
      image(images[frame],x_loc,y_loc);
      frame++;
      if(frame > number_of_frames-1) {
        running = false;
      }
    }
    else {
      image(images[number_of_frames-1],x_loc,y_loc);
    }
  }
}

